﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data.OleDb
Imports System.Data.SqlClient

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<ToolboxItem(False)> _
Public Class SlideService
    Inherits System.Web.Services.WebService


    'Public Function GetSlides() As AjaxControlToolkit.Slide()


    '    'MySlides(0) = New AjaxControlToolkit.Slide("pictures/red.jpg", "Image Name 0", "Image Description 0")
    '    'MySlides(1) = New AjaxControlToolkit.Slide("pictures/green.jpg", "Image Name 1", "Image Description 1")
    '    'MySlides(2) = New AjaxControlToolkit.Slide("pictures/yellow.jpg", "Image Name 2", "Image Description 2")
    '    'MySlides(3) = New AjaxControlToolkit.Slide("pictures/blue.jpg", "Image Name 3", "Image Description 3")
    '    'MySlides(4) = New AjaxControlToolkit.Slide("pictures/orange.jpg", "Image Name 4", "Image Description 4")
    '    'Return MySlides

    '    Dim x As Integer
    '    Dim i As Integer

    '    Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    '    Dim SqlString As String = "select top 5 Picture, Name, Description from Profiles where userid is not null "
    '    Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
    '    cmd.CommandType = CommandType.Text
    '    'cmd.Parameters.AddWithValue("@f1", Request.Params("PID"))
    '    oleDbConn.Open()

    '    Dim dr As OleDbDataReader = cmd.ExecuteReader()
    '    Dim al As New ArrayList()
    '    Dim MySlides(x - 1) As AjaxControlToolkit.Slide
    '    x = al.Count
    '    i = 0

    '    While dr.Read()

    '        Dim pathstr As String = dr("Picture")
    '        Dim Namestr As String = dr("Name")
    '        Dim descriptionstr As String = dr("Description")
    '        MySlides(i) = New AjaxControlToolkit.Slide(pathstr, Namestr, descriptionstr)
    '        i = i + 1

    '    End While

    '    dr.Close()

    '    Return MySlides

    'End Function

    <WebMethod()> _
    Public Function GetSlides() As AjaxControlToolkit.Slide()

        Dim newdt As New DataTable()
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim SqlString As String = "select top 5 UserID, Picture, Name, Description from Profiles where userid is not null order by ID desc "
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        oleDbConn.Open()

        Dim newda As New OleDbDataAdapter(cmd)
        newda.Fill(newdt)
        Dim slides As AjaxControlToolkit.Slide() = New AjaxControlToolkit.Slide(newdt.Rows.Count - 1) {}

        For i As Integer = 0 To newdt.Rows.Count - 1

            Dim Imagepath As String = newdt.Rows(i).Item("Picture")
            Dim Name As String = "<a href='ProfilePage.aspx?UID=" & newdt.Rows(i).Item("UserID") & "'>" & newdt.Rows(i).Item("Name") & "</a>"
            'Dim Description As String = newdt.Rows(i).Item("Description")
            slides(i) = New AjaxControlToolkit.Slide(Imagepath, Name, "Description")

        Next
        Return slides
        oleDbConn.Close()

    End Function

End Class